package com.year_23.april;

import java.util.ArrayList;
import java.util.List;

/**
 * 1023  驼峰式匹配 https://leetcode.cn/problems/camelcase-matching/
 *
 * @Author jsh
 * @Date 2023/4/15 23:58
 * @Version 1.0
 */
public class Day14 {
    public static void main(String[] args) {
        String[] queries = {"FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"};
        String pattern = "FoBa";
        List<Boolean> booleanList = camelMatch(queries, pattern);
        for (Boolean aBoolean : booleanList) {
            System.out.println(aBoolean);
        }
    }

    public static List<Boolean> camelMatch(String[] queries, String pattern){
        List<Boolean> booleanList = new ArrayList<>();
        for (String query : queries) {
            booleanList.add(Match(query, pattern));
        }
        return booleanList;
    }

    public static boolean Match(String query, String pattern){
        int left = 0;
        for (int i = 0; i < query.length(); i++) {
            if (left < pattern.length() && pattern.charAt(left) == query.charAt(i)){
                left++;
            }else if (query.charAt(i) < 'a'){
                left = 0;
            }
        }

        return left == pattern.length();
    }
}
